package com.bjsxt.IO;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.IOException;

public class FileUtilsTest {

    public static void main(String[] args) throws IOException {

        String con = FileUtils.readFileToString(new File("G:\\2021-09-01-java学习\\java300\\src\\com\\bjsxt\\IO\\a.txt"),"utf-8");
        System.out.println(con);

        FileUtils.copyDirectory(new File("G:\\2021-09-01-java学习\\java300\\src\\com\\bjsxt\\IO"), new File("G:\\2021-09-01-java学习\\java300"), new FileFilter() {
            @Override
            public boolean accept(File pathname) {
                if (pathname.isDirectory()||pathname.getName().endsWith("txt")){
                    return true;
                }
                return false;
            }
        });

        //IOutils
        String cont = IOUtils.toString(new FileInputStream("G:\\2021-09-01-java学习\\java300\\src\\com\\bjsxt\\IO\\a.txt"));
        System.out.println(cont);
    }
}
